package net.j4love.algorithm.chapter1;

import org.junit.jupiter.api.Test;

import java.util.Stack;

/**
 * @author he peng
 * @create 2017/10/16 17:49
 * @see
 */
public class JavaStackTest {

    // 1.3.2 给定以下输入 ， java Stack 的输出是什么？
    // it was - the best - of times - it was - the
    @Test
    public void test() throws Exception {
        Stack<String> stack = new Stack<>();
        stack.push("it was");
        stack.push("the best");
        stack.push("of times");
        stack.push("it was");
        String pushResult = stack.push("the");
        System.out.println("push result = " + pushResult);

        System.out.println("stack = " + stack);
        // LIFO
        System.out.println("pop = " + stack.pop());
        System.out.println("poped stack = " + stack);

    }

    // 1.3.4 判断括号是否配对完整，例如 ： [()]{}{[()()]()} 程序应该打印 true
    // 对于 [(]) 则打印 false
    @Test
    public void parentheses() throws Exception {

        String target = "[()]{}{[()()]()}";
        if (target.length() % 2 == 1) {
            System.out.println(false);
            return;
        }

        String firstHalf = target.substring(0, target.length() / 2);
        String lastHalf = target.substring(target.length() / 2);

        Stack<Character> stack_1 = new Stack<>();
        Stack<Character> stack_2 = new Stack<>();

    }
}
